'use client';

import { OAUTH_CLIENT_API_TYPE_KEY } from '@/lib/constant';
import type { IOauthClientApi } from '@/interfaces';
import { formatDate } from '@/lib/tool';
import Link from 'next/link';

export default function DetailsOauthClientApiInfo({
  details,
}: {
  details: IOauthClientApi;
}) {
  return (
    <div className="row">
      <div className="col">
        <div className="card">
          <div className="card-header bg-transparent text-muted">
            <i className="bi bi-info-square me-2"></i>
            {details.name}
          </div>
          <div className="card-body">
            <div className="table-responsive">
              <table className="table table-hover align-middle table-striped">
                <thead>
                  <tr className="text-nowrap">
                    <th scope="col" className="fw-normal">
                      ID
                    </th>
                    <th scope="col" className="fw-normal">
                      {details.id}
                    </th>
                  </tr>
                </thead>
                <tbody>
                  {[...Object.keys(details)]
                    .filter((item) => !['id'].includes(item))
                    .map((item) => {
                      return (
                        <tr key={item} className="text-nowrap">
                          <td>
                            {item === 'createdBy' && '创建用户'}

                            {item === 'updatedBy' && '更新用户'}

                            {item === 'creatorAlias' && '创建者别名'}

                            {item === 'updaterAlias' && '更新者别名'}

                            {item === 'createdOn' && '创建时间'}

                            {item === 'updatedOn' && '更新时间'}

                            {item === 'deleted' && '是否删除'}

                            {item === 'clientId' && '客户端 Id'}

                            {item === 'name' && '名称'}

                            {item === 'overview' && '概述'}

                            {item === 'category' && '分类'}

                            {item === 'doc' && '文档'}

                            {item === 'upperLimit' && '上限'}

                            {item === 'type' && '类型'}
                          </td>
                          <td>
                            {item === 'createdBy' && details[item]}

                            {item === 'updatedBy' && details[item]}

                            {item === 'creatorAlias' && details[item]}

                            {item === 'updaterAlias' && details[item]}

                            {item === 'createdOn' && formatDate(details[item])}

                            {item === 'updatedOn' && formatDate(details[item])}

                            {item === 'deleted' && details[item] + ''}

                            {item === 'name' && details[item]}

                            {item === 'overview' && details[item]}

                            {item === 'category' && details[item]}

                            {item === 'doc' && details[item] ? (
                              <Link
                                href={details[item]!}
                                className="text-decoration-underline-hover text-decoration-none"
                              >
                                {details[item]}
                              </Link>
                            ) : (
                              ''
                            )}

                            {item === 'upperLimit' &&
                              (details[item] === 0 ? '无上限' : details[item])}

                            {item === 'type' &&
                              OAUTH_CLIENT_API_TYPE_KEY[details[item]]}
                          </td>
                        </tr>
                      );
                    })}
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}
